<?php


namespace LazadaApi\Services;


use phpDocumentor\Reflection\Types\Null_;

class LazadaETicksService extends BaseLazadaService
{
    /**
     * 使用代码之前的回调接口
     *
     * @see https://open.lazada.com/doc/api.htm?spm=a2o9m.11193531.0.0.2c3d6bbe6GdZ0B#/api?cid=21&path=/eticket/ma/available
     *
     * @param string      $bizType
     * @param string      $code
     * @param string      $serialNum
     * @param string      $outerId
     * @param string      $consumeNum
     * @param string      $consumeStoreId
     * @param string|null $posId
     *
     * @return mixed
     * @throws \Exception
     */
    public function maAvailable(int $bizType, string $code, string $serialNum, string $outerId, int $consumeNum, string $consumeStoreId, string $posId = null)
    {
        $this->addApiParam('biz_type', $bizType);
        $this->addApiParam('code', $code);
        $this->addApiParam('serial_num', $serialNum);
        $this->addApiParam('outer_id', $outerId);
        $this->addApiParam('consume_num', $consumeNum);
        $this->addApiParam('consumeStoreId', $consumeStoreId);
        if (null !== $posId) {
            $this->addApiParam('pos_id', $posId);
        }

        return $this->post('/eticket/ma/available');
    }

    /**
     * @see https://open.lazada.com/doc/api.htm?spm=a2o9m.11193531.0.0.2c3d6bbe6GdZ0B#/api?cid=21&path=/eticket/ma/consume
     *
     * @param string      $bizType
     * @param string      $code
     * @param int         $num
     * @param string      $serialNum
     * @param string      $outerId
     * @param string      $consumeNum
     * @param string      $consumeStoreId
     * @param string|null $posId
     *
     * @return mixed
     * @throws \Exception
     */
    public function maConsume(int $bizType, string $code, int $num, string $serialNum, string $outerId, int $consumeNum, string $consumeStoreId, string $posId = null)
    {
        $this->addApiParam('biz_type', $bizType);
        $this->addApiParam('code', $code);
        $this->addApiParam('num', $num);
        $this->addApiParam('serial_num', $serialNum);
        $this->addApiParam('outer_id', $outerId);
        $this->addApiParam('consume_num', $consumeNum);
        $this->addApiParam('consumeStoreId', $consumeStoreId);
        if (null !== $posId) {
            $this->addApiParam('pos_id', $posId);
        }

        return $this->post('/eticket/ma/consume');
    }

    /**
     * @see https://open.lazada.com/doc/api.htm?spm=a2o9m.11193531.0.0.2c3d6bbe6GdZ0B#/api?cid=21&path=/eticket/ma/failsend
     *
     * @param int    $bizType 3001
     * @param string $subCode isv.fail-send-no-stock
     * @param string $outerId 193962300049720
     * @param string $subMsg  inventory not enough
     *
     * @return mixed
     * @throws \Exception
     */
    public function maFailSend(int $bizType, string $subCode, string $outerId, string $subMsg)
    {
        $this->addApiParam('biz_type', $bizType);
        $this->addApiParam('sub_code', $subCode);
        $this->addApiParam('outer_id', $outerId);
        $this->addApiParam('sub_msg', $subMsg);

        return $this->post('/eticket/ma/failsend');
    }

    /**
     * @see https://open.lazada.com/doc/api.htm?spm=a2o9m.11193531.0.0.2c3d6bbe6GdZ0B#/api?cid=21&path=/eticket/ma/send
     *
     * @param int    $bizType   3001
     * @param array  $isvMaList {   "code": "abc123",   "num": 1 } Max Length: 200
     * @param string $outerId   1753340805138544
     *
     * @return mixed
     * @throws \Exception
     */
    public function maSend(int $bizType, array $isvMaList, string $outerId)
    {
        $this->addApiParam('biz_type', $bizType);
        $this->addApiParam('isv_ma_list', $isvMaList);
        $this->addApiParam('outer_id', $outerId);

        return $this->post('/eticket/ma/send');
    }
}